<!--
/*
 *      progress.html
 *
 *      Copyright 2009 CSS Corporation
 *      Author: CSS Labs.
 *
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */
-->

<html lang="en" >
<head>
    <title>Downloading Logs</title>
    <script  type="text/javascript">
        
        MAX = 20;
        DURATION = 250;
        CH = '|';
        
        str = CH;
        
        function progressbar() {
            if (str.length > MAX){
                str = CH;
            } else {
                str = str + CH;
            }
            document.getElementById("pb").innerHTML = str;
            setTimeout(progressbar, DURATION);
        }
        function querySt(ji) {
            hu = window.location.search.substring(1);
            gy = hu.split("&");
            for (i=0;i<gy.length;i++) {
                ft = gy[i].split("=");
                if (ft[0] == ji) {
                    return ft[1];
                }
            }
        }
        
        function getaddress(){
            address = window.location.href;
            newadd = address.replace(/[^\/]+$/, "");
            return newadd;
        }
        
        function check(){
            bucket = querySt("bucket");
            url = getaddress() +'awstats/cbanalytics.htm';
            url = url + "?bucket=" + bucket;
            getWebpage(url);
        }
        
        function getWebpage(url) {
	    if (window.XMLHttpRequest) {
		xmlHttp=new XMLHttpRequest(); // code for all new browsers
	    }
	    else if (window.ActiveXObject) {
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");  // code for IE5 and IE6
	    }
	    var ts = (new Date).getTime();
	    url = url + "&ts=" + ts;	//to prevent browser from caching response
	    if (xmlHttp!=null) {
		xmlHttp.onreadystatechange=state_change;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	    }
	    else {
		alert("Your browser does not support XMLHTTP.");
	    }
        }
	
	function  state_change() {
	    if (xmlHttp.readyState==4) {// 4 = "loaded"
		if (xmlHttp.status==200) {// 200 = "OK"
                    result = xmlHttp.responseText;
                    switch (result) {
                        case "ok":
                            file = 'awstats/awstats.pl?config=' + bucket + '&update=1&status=1&upd=1';
                            break;
                        case "alert":
                            file = 'alert.html';
                            break;
                        case "fails":
                            file = 'error_filemissing.html';
                            break;
                        default:
                            file = 'error_logging_failed.html';
                            break;
                    }
                    redirect(file);
		}
		else {
		  alert("Problem retrieving XML data:" + xmlhttp.statusText);
		}
	    }
	}
        
        function redirect(file){
            var redir = getaddress() + file;
            window.location = redir;
        }
        
        function init(){
            check();
            progressbar();
        }
    </script>
    
</head>
<body>
    <br><br><br><br><br>
    <label style="margin-left:35%;">
	<font style='color:#3366cc; font-family: Verdana, Arial, Helvetica, sans-serif; font-size:15px; font-weight:bold;'>CloudBuddy Analytics is at work. Please wait...</font>
    </label>
    <div>
        <label id="pb" style="position:absolute; margin-top:5%; margin-left:43%;color:#A5CF3C;font-weight:bolder;font-size:25px;">
            |
        </label>
    </div>
    <script>
        init();
    </script>
</body>
</html>
